import gwc.domain.*

def toJSON = {msg ->
	"{id : '${msg.id}', content : '${msg.content}', user : '${msg.user.name}'}"
}
def user = User.get(params.user)


def message = new Message(user : user, content : params.msg)

MessageQueue.instance.add(message)



println "{messages : [" + MessageQueue.instance.getFrom((params.lastMsgId ? Long.valueOf(params.lastMsgId) : 0)).collect({toJSON(it)}).join(",") + "]}"